
#include <emscripten.h>
#include <cmath>

extern "C" {
    EMSCRIPTEN_KEEPALIVE
    double add(double a, double b) {
        return a + b;
    }
    
    EMSCRIPTEN_KEEPALIVE
    double subtract(double a, double b) {
        return a - b;
    }
    
    EMSCRIPTEN_KEEPALIVE
    double multiply(double a, double b) {
        return a * b;
    }
    
    EMSCRIPTEN_KEEPALIVE
    double divide(double a, double b) {
        if (b == 0) return 0;
        return a / b;
    }
    
    EMSCRIPTEN_KEEPALIVE
    double power(double base, double exponent) {
        return pow(base, exponent);
    }
    
    EMSCRIPTEN_KEEPALIVE
    double squareRoot(double x) {
        if (x < 0) return -1;
        return sqrt(x);
    }
}
